#!/usr/bin/env python
# -*- coding: utf-8 -*-
# train grade
# 記入方法:(2011/01/13 by kuma35)
# 1.OUD_BLOCK〜OUD_BLOCK_ENDまでが1つ分の定義です。
# u"Ressyasyubetsu"+OUD_BLOCK,
# u"Syubetsumei=普通",
# u"JikokuhyouMojiColor=00000000",
# u"DiagramSenColor=00000000",
# u"DiagramSenStyle=SenStyle_Jissen",
# u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
# OUD_BLOCKEND,
# 2 ] の直前に加えてください。
# 3.Syubetsumeiの値でえきから時刻表の列車名から判別します。
# 4.時刻表の種別表示が不要の時はRyakusyouの行は不要。
# 5.色替えの必要が無くても列車種別は分けておくと何かと便利です。
# ※このファイルはParseEkikara.pyとOudiaFormat.pyで利用されます。
#   ParseEkikara.py:Syubetsumeiより正規表現生成
#   OudiaFormat.py:下記の順番を元に列車種別コードを取得します。
import re
from OudiaFormatDefs import *

OUD_TRAIN_GRADE = [u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=普通",
                   u"JikokuhyouMojiColor=00000000",
                   u"DiagramSenColor=00000000",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=快速",
                   u"Ryakusyou=快速",
                   u"JikokuhyouMojiColor=0000C000",
                   u"DiagramSenColor=0000C000",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=急行",
                   u"Ryakusyou=急行",
                   u"JikokuhyouMojiColor=00FFA500",
                   u"DiagramSenColor=00FFA500",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=特急",
                   u"Ryakusyou=特急",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=快特",
                   u"Ryakusyou=快特",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=準急",
                   u"Ryakusyou=準急",
                   u"JikokuhyouMojiColor=0000C000",
                   u"DiagramSenColor=0000C000",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線のぞみ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線ひかり",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線こだま",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線つばめ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線やまびこ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線つばさ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線はやて",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線Ｍａｘやまびこ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線なすの",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線とき",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"JikokuhyouMojiColor=00000000",
                   u"DiagramSenColor=00000000",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線たにがわ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線Ｍａｘとき",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線あさま",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=ライナー",
                   u"Ryakusyou=快速",
                   u"JikokuhyouMojiColor=00000000",
                   u"DiagramSenColor=00000000",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   u"Ressyasyubetsu" + OUD_BLOCK,
                   u"Syubetsumei=新幹線はやぶさ",
                   u"Ryakusyou=新幹",
                   u"JikokuhyouMojiColor=000000FF",
                   u"DiagramSenColor=000000FF",
                   u"DiagramSenStyle=SenStyle_Jissen",
                   u"StopMarkDrawType=EStopMarkDrawType_DrawOnStop",
                   OUD_BLOCKEND,
                   ]


class TrainGrade:
    def gradeNameList(self, gradeList):
        nameList = []
        reName = re.compile(u"^Syubetsumei=(.*)$", re.U)
        for line in gradeList:
            mName = reName.search(line)
            if mName:
                nameList.append(mName.group(1))
        return nameList

    def __init__(self, logger, gradeList=None):
        self.logger = logger       # logging object
        if gradeList:
            self.gradeList = gradeList
        else:
            self.gradeList = OUD_TRAIN_GRADE
        self.nameList = self.gradeNameList(self.gradeList)
        reTypeStr = u"^(.*)(" + u"|".join(self.nameList) + u")(.*)"
        self.logger.debug(u"reType=[%s]" % (reTypeStr))
        self.reType = re.compile(reTypeStr, re.U)
        self.nameMap = {}
        for i, v in enumerate(self.nameList):
            self.nameMap[v] = i

    def getCode(self, gradeName):
        if gradeName in self.nameMap:
            return self.nameMap[gradeName]
        else:
            return 0
